home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-17 | 24.6 KB | 716 lines | [TEXT/MPS ] |
- {–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
-
- PROJECT: Threads Traffic Simulation
-
- FILE: UEventMgmt.p
-
- LANGUAGE: MPW Pascal (version 3.2)
-
- DESCRIPTION: This is the main clearing house for Event Handling. Once the application
- is initialized program control is transfered here. All Event dispatching
- then takes place from here.
-
- AUTHOR(S): William H. Knott
- Apple Computer
- Cupertino, CA 95014
- AppleLink : KNOTT
-
- Change History:
- 3/8/93 ewa Update to new gestalt names
-
- VERSION(S): 1.0 14-Aug-92 WHK Brand New Today.
-
- –––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––}
-
- UNIT UEventMgmt;
-
- INTERFACE
-
- USES
- MemTypes, QuickDraw, OSIntf, ToolIntf, PackIntf, Traps, GestaltEqu,
-
- Threads,
-
- UApplication, UInitMgmt, USimulation, UDocument;
-
- PROCEDURE Segment_UEventMgmt;
-
- PROCEDURE RunApplication;
- PROCEDURE CleanUpOnExit;
-
- PROCEDURE SetMenuBarState;
-
- IMPLEMENTATION
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { Segment_UEventMgmt }
- { }
- { Provided as a convenient way of unloading the UEventMgmt segment when needed }
- { }
- { October 13, 1991 Created by William Knott }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE Segment_UEventMgmt;
- BEGIN
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { SetMenuItemState }
- { }
- { Sets the given menu item to either an enable or disabled state. }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE SetMenuItemState(theMenu : MenuHandle;
- theItem : INTEGER;
- state : BOOLEAN);
- BEGIN
- IF state THEN
- EnableItem(theMenu, theItem)
- ELSE
- DisableItem(theMenu, theItem)
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { SetMenuBarState }
- { }
- { Set the states of the menus as approprate. }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE SetMenuBarState;
- VAR
- theMenu : MenuHandle;
- meFrontWind : BOOLEAN;
- docWindFront : BOOLEAN;
- theWind : WindowPtr;
- daInFront : BOOLEAN;
- BEGIN
- theWind := FrontWindow;
- meFrontWind := (theWind <> NIL) & ((WindowPeek(theWind)^.windowKind = 8) | (WindowPeek(theWind)^.windowKind = 2));
- docWindFront := meFrontWind & IsWindowADocument(theWind);
- daInFront := (FrontWindow <> NIL) & NOT meFrontWind;
-
- theMenu := GetMenu(rFileMenuID);
- SetMenuItemState(theMenu, iFileQuitItem, TRUE); { Only enable quit, it is the only one we are using right now! }
-
- SetMenuItemState(theMenu, 0 , (gDocument <> NIL));
- DrawMenuBar;
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { YieldFilter }
- { }
- { Generic routine to handle a dialog box requiring only an OK button to be hit. }
- { The OK button needs to be the first item in the dialog's DITL. If this routine }
- { is being called, an alert should probably be used instead. }
- { }
- { July 14, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- FUNCTION YieldFilter (theDialog : DialogPtr;
- VAR theEvent : EventRecord;
- VAR itemHit : INTEGER) : BOOLEAN;
- CONST
- kEnterKey = 3;
- kReturnKey = 13;
- VAR
- error : OSErr;
- holdPort : GrafPtr;
- aItem : Handle;
- aItemType : INTEGER;
- aRect : RECT;
- key : Char;
- oldTick : LONGINT;
- BEGIN
- GetPort(holdPort);
- error := YieldToAnyThread;
- SetPort(holdPort);
- YieldFilter := FALSE;
-
- IF theEvent.what = updateEvt THEN
- BEGIN
- GetDItem(theDialog, 1, aItemType, aItem, aRect);
- PenSize(3,3);
- InsetRect(aRect, -4, -4);
- FrameRoundRect(aRect, 16, 16);
- PenSize(1,1);
- END;
-
- IF theEvent.what = keyDown THEN
- BEGIN
- key := CHR(BAnd(theEvent.message, charCodeMask));
- IF Ord(key) IN [kEnterKey, kReturnKey] THEN
- BEGIN
- itemHit := 1;
- oldTick := TickCount;
- GetDItem(theDialog, 1, aItemType, aItem, aRect);
- HiliteControl(ControlHandle(aItem),1);
- repeat
- until TickCount > (oldTick + 3);
- HiliteControl(ControlHandle(aItem),0);
- YieldFilter := TRUE;
- END;
- END;
-
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoOKDialogImplementation }
- { }
- { Generic routine to handle a dialog box requiring only an OK button to be hit. }
- { The OK button needs to be the first item in the dialog's DITL. If this routine }
- { is being called, an alert should probably be used instead. }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoOKDialogImplementation(dialogID : INTEGER);
- VAR
- theDialog : DialogPtr;
- itemHit : INTEGER;
- oldPort : GrafPtr;
- error : OSErr;
- BEGIN
- GetPort(oldPort);
- theDialog := GetNewDialog(dialogID,NIL, Pointer(-1));
- IF theDialog <> NIL THEN
- BEGIN
- SetPort(theDialog);
- ShowWindow(theDialog);
- repeat
- ModalDialog(@YieldFilter,itemHit);
- until itemHit = 1;
- DisposDialog(theDialog);
- END
- ELSE
- Sysbeep(1);
- SetPort(oldPort);
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoNotYetImplemented }
- { }
- { Display the dialog when a non-implemented function is chosen }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoNotYetImplemented;
- BEGIN
- DoOKDialogImplementation(rNotYetImplementedID);
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoAboutBox }
- { }
- { Display the about box, currently a boring static dialog. }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoAboutBox;
- BEGIN
- DoOKDialogImplementation(rAboutDlogID);
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoDeskAcc }
- { }
- { Given the desk accessory that was chosen from the apple menu, this procedure will }
- { launch the selected desk accessory. }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoDeskAcc( item : INTEGER );
- VAR
- savePort : GrafPtr;
- refNum : Integer;
- dName : Str255;
- theMenu : MenuHandle;
- BEGIN
- GetPort(savePort);
- theMenu := GetMenu(rAppleMenuID);
- GetItem(theMenu, Item, dName);
- refNum := OpenDeskAcc(dName);
- SetPort(savePort);
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoAppleMenu }
- { }
- { If a menu event occurs in the apple menu, there are two distinct cases that we }
- { need to handle. The first case being the about item, in which we simply display }
- { the about box. If the item chosen was not the about item we must open the }
- { selected desk accessory. }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoAppleMenu(menuItem : INTEGER);
- BEGIN
- IF menuItem = iAboutItem THEN
- DoAboutBox
- ELSE
- BEGIN
- DoDeskAcc(menuItem);
- END;
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoWindowClose }
- { }
- { Close the given window. Currently this document only has a single window,so very }
- { little redirection is being done. }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoWindowClose(whichWind : WindowPtr);
- BEGIN
- IF whichWind <> NIL THEN
- BEGIN
- IF IsWindowADocument(whichWind) THEN
- CloseDocument(whichWind);
- END;
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoQuitApplication }
- { }
- { Sets the global variable gDone to TRUE. It then closes any open documents. }
- { This quit can be cancelled by the close document routine. }
- { }
- { October 13, 1991 WHK Created today }
- { July 20, 1991 WHK Added BeginThreadCritical to solve some problems like }
- { drawing to the screen. }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoQuitApplication;
- VAR
- error : OSErr;
- BEGIN
- error := ThreadBeginCritical; { We still have threads spinning away and I am about ready to snatch the }
- { document window out from underneath them, not a very nice thing to do, but }
- { should eliminate some of those unexpected crashes. }
- gDone := TRUE;
- CloseAllOpenDocuments;
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoFileMenu }
- { }
- { The menu item that has been selected was somewhere in the File menu. Therefore }
- { program flow is directed to the proper routine. }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoFileMenu(menuItem : INTEGER);
- BEGIN
- CASE menuItem OF
- iFileNewItem:
- BEGIN
- CreateNewDocument;
- DebugStr('Should not be selectable');
- END;
- iFileOpenItem: DoNotYetImplemented;
- iFileCloseItem: DoWindowClose(FrontWindow);
- iFileSaveItem: DoNotYetImplemented;
- iFileSaveAsItem: DoNotYetImplemented;
- iFileRevertItem: DoNotYetImplemented;
- iFilePSetupItem: DoPageSetupDoc(FrontWindow);
- iFilePrintItem: DoPrintDocument(FrontWindow);
- iFileQuitItem: DoQuitApplication;
- END;
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoEditMenu }
- { }
- { The menu item that has been selected was somewhere in the Edit menu. Therefore }
- { program flow is directed to the proper routine. The Edit Menu is not yet }
- { implemented }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoEditMenu(menuItem : INTEGER);
- BEGIN
- CASE menuItem OF
- iEditUndoItem: DoNotYetImplemented;
- iEditCutItem: DoNotYetImplemented;
- iEditCopyItem: DoNotYetImplemented;
- iEditPasteItem: DoNotYetImplemented;
- iEditClearItem: DoNotYetImplemented;
- END;
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoTestMenu }
- { }
- { The menu item that has been selected was somewhere in the Test menu. Therefore }
- { program flow is directed to the proper routine. }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoTestMenu(menuItem : INTEGER);
- BEGIN
- IF menuItem = 1 THEN
- CreateFreeThreadsForCars
- ELSE
- MarkACarForDestruction;
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoMenuCommand }
- { }
- { The last event was a menu command, either a mouse driven one or a command key }
- { selection. From here, it is sent on to individual menu handlers. }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoMenuCommand(whichmenu : LONGINT);
- VAR
- menuID : INTEGER;
- menuItem : INTEGER;
- BEGIN
- menuItem := LoWord(whichmenu);
- menuID := HiWord(whichmenu);
- CASE menuID OF
- rAppleMenuID: DoAppleMenu(menuItem);
- rFileMenuID: DoFileMenu(menuItem);
- rEditMenuID: DoEditMenu(menuItem);
- rTestMenuID: DoTestMenu(menuItem);
- OTHERWISE ;
- END;
- HiliteMenu(0);
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { GrowTheWindow }
- { }
- { Window growing is a unique case that should be handled individually by each }
- { window kind that exists in an application. For this reason, the GrowTheWindow }
- { routine passes the grow event onto the proper handler. }
- { }
- { October 13, 1991 WHK Created today }
- { October 17, 1991 WHK Updated handling of document event so that they are }
- { all routed through a single procedure. }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE GrowTheWindow(theWindow : WindowPtr;
- theEvent : EventRecord);
- BEGIN
- IF IsWindowADocument(theWindow) THEN
- HandleDocumentEvent(theWindow, theEvent);
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoMouseDownInContent }
- { }
- { A mousedown occured within the content region of a window. Since the window may }
- { react its own unique way depending on whether it is frontmost or not, I will pass }
- { the event onto the window that it occured in. }
- { }
- { October 13, 1991 WHK Created today }
- { October 17, 1991 WHK Updated handling of document event so that they are }
- { all routed through a single procedure. }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoMouseDownInContent(theWindow : WindowPtr;
- theEvent : EventRecord);
- BEGIN
- IF IsWindowADocument(theWindow) THEN
- HandleDocumentEvent(theWindow, theEvent);
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoMouseDown }
- { }
- { Most window mousedowns can be handled generically regardless of the window they }
- { occur in, the exceptions being the content, grow, zoomIn, and zoomOut regions. }
- { So all the generic areas are handled here, with special cases being sorted }
- { elsewhere. }
- { }
- { October 13, 1991 WHK Created today }
- { October 17, 1991 WHK Modified to support mdown in content area Added }
- { proper support for mouse down in window not in front }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoMouseDown(theEvent : EventRecord);
- VAR
- theWind : WindowPtr;
- where : INTEGER;
- bounds : RECT;
- BEGIN
- where := FindWindow(theEvent.where,theWind);
-
- IF (where IN [inDrag,inGoAway,inGrow,inContent,inZoomIn,inZoomOut]) THEN
- IF (theWind <> NIL) & (theWind <> frontWindow) THEN
- SelectWindow(theWind);
- CASE where OF
- inMenuBar: DoMenuCommand(MenuSelect(theEvent.where));
- inDrag: DragWindow(theWind,theEvent.where,screenbits.bounds);
- inGoAway: IF TrackGoAway(theWind,theEvent.where) THEN DoWindowClose(theWind);
- inGrow: GrowTheWindow(theWind,theEvent);
- inContent: DoMouseDownInContent(theWind, theEvent);
- (*
- inSysWindow,inZoomIn,inZoomOut
- *)
- OTHERWISE
- ;
- END;
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoKeyDown }
- { }
- { A keydown has occured, we need to determine whether the command key was down as }
- { well. If it is a command key combination, we pass control onto the menu command }
- { handler, else it is passed to the document window. }
- { }
- { October 13, 1991 WHK Created today }
- { October 17, 1991 WHK Updated handling of document event so that they are }
- { all routed through a single procedure. }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoKeyDown(theEvent : EventRecord);
- VAR
- key : Char;
- BEGIN
- key := CHR(BAnd(theEvent.message, charCodeMask));
- IF BAnd(theEvent.modifiers, cmdKey) <> 0 THEN
- DoMenuCommand(MenuKey(key))
- ELSE
- IF IsWindowADocument(FrontWindow) THEN
- HandleDocumentEvent(FrontWindow, theEvent);
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoUpdate }
- { }
- { A update event has occured, so pass the event on to the approprate window. }
- { }
- { October 13, 1991 WHK Created today }
- { October 17, 1991 WHK Updated handling of document event so that they are }
- { all routed through a single procedure. }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoUpdate(theEvent : EventRecord);
- VAR
- theWind : WindowPtr;
- holdPort : GrafPtr;
- BEGIN
- theWind := WindowPtr(theEvent.message);
-
- IF IsWindowADocument(theWind) THEN
- HandleDocumentEvent(theWind, theEvent);
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoActivate }
- { }
- { Whenever a window is brought to the front or moved from the front behind other }
- { windows an activate event occurs. This is where controls should be highlighted/ }
- { dehighlighted and menu items should be enabled/disabled approprately. }
- { }
- { October 13, 1991 WHK Created today }
- { October 17, 1991 WHK Updated handling of document event so that they are }
- { all routed through a single procedure. }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoActivate(theEvent : EventRecord);
- VAR
- theWind : WindowPtr;
- BEGIN
- theWind := WindowPtr(theEvent.message);
-
- IF IsWindowADocument(theWind) THEN
- HandleDocumentEvent(theWind, theEvent);
-
- SetMenuBarState;
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoApp4Evt }
- { }
- { The application is either being switched in or out of under multifinder. The }
- { approprate actions need to be performed to handle window and control appearence. }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoApp4Evt(theEvent : EventRecord);
- BEGIN
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { HandleEvent }
- { }
- { An event has occured and now needs to be handled in the approprate area. This is }
- { where currently unsupported Apple Events will need to be added. }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE HandleEvent(theEvent : EventRecord);
- BEGIN
- CASE theEvent.what OF
- mouseDown: DoMouseDown(theEvent);
- keyDown: DoKeyDown(theEvent);
- AutoKey: DoKeyDown(theEvent);
- UpdateEvt: DoUpdate(theEvent);
- ActivateEvt: DoActivate(theEvent);
- App4Evt: DoApp4Evt(theEvent);
- OTHERWISE
- ;
- END;
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { DoMainEventLoop }
- { }
- { No longer a loop but a simple check to see if an event has occured. If it has, }
- { then the event is passed on to the HandleEvent routine. The advantage of having }
- { this check outside the repeat-until loop allows for event handling during }
- { program processing. }
- { }
- { October 13, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE DoMainEventLoop;
- VAR
- tempStr : Str255;
- theEvent : EventRecord;
- error : OSErr;
- BEGIN
- error := YieldToAnyThread;
- IF error <> noErr THEN DebugStr('Trouble yielding in main event loop');
-
- IF WaitNextEvent(everyEvent,theEvent, 1, NIL) THEN
- HandleEvent(theEvent);
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { ThreadsIsAvailable }
- { }
- { Uses gestalt to verify the availability of the Thread Manager. Assumption that }
- { gestalt is present. }
- { }
- { July 31, 1991 WHK Created today }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- FUNCTION ThreadsIsAvailable : BOOLEAN;
- VAR
- error : OSErr;
- response : LONGINT;
- BEGIN
- ThreadsIsAvailable := FALSE;
- error := Gestalt(gestaltThreadMgrAttr, response);
- IF error = noErr THEN
- IF BTST(response, gestaltThreadMgrPresent) THEN
- ThreadsIsAvailable := TRUE;
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { RunApplication }
- { }
- { Simply run throught the main event loop until gDone is TRUE. }
- { }
- { October 13, 1991 WHK Created today }
- { July 31, 1991 WHK Added check to see if Threads Manager is available. }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE RunApplication;
- VAR
- itemHit : INTEGER;
- BEGIN
- IF ThreadsIsAvailable THEN
- BEGIN
- CreateNewDocument;
- repeat
- DoMainEventLoop;
- until gDone;
- END
- ELSE
- BEGIN
- itemHit := StopAlert(rNoThreadMgrAlertID, NIL);
- END;
- END;
-
- {$S EventMgmt}
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- { }
- { CleanUpOnExit }
- { }
- { The program has quit and this is the last routine that will be called before the }
- { application quits. Any last minute cleaning up and preference saving will need }
- { to be done here. }
- { }
- { October 13, 1991 Created by William Knott }
- { }
- {––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––-––}
- PROCEDURE CleanUpOnExit;
- BEGIN
- { Nothing to clean up right now. In all honesty, probably should dispose of all the threads here. }
- END;
-
- END.